/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AltaProves.java
 *
 * Created on 04-may-2012, 10:10:30
 */
package client.subsistema2;

import beans.Prova;
import beans.RespostaCorrecta;
import beans.Ronda;
import beans.Constants;
import common.EOlympicsException;
import common.RemoteInterface;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

/**
 *
 * @author Daniel
 */
public class AltaProves extends javax.swing.JFrame {

    /** Creates new form AltaProves */
    public AltaProves(RemoteInterface pRemoto, int usuari) {
        initComponents();        
        maxim=Constants.NUM_MAX_PARTICIPANTS_PROVA;
        minim=Constants.NUM_MIN_PARTICIPANTS_PROVA;
        ocultarEliminatoria(false);
        limpiar();
        bloquejar(false);
        codiUsuari=usuari;
        txtNum="Núm.";
        txtResp="Resp.";
        bundle = java.util.ResourceBundle.getBundle("i18n/subsistema2/messagesSubsistema2"); // NOI18N
        remoto=pRemoto;
        
        // quan sintegri llevar això i comentar al main()
        /*
        try {

                    remoto=(RemoteInterface)Naming.lookup(url);
        } catch (NotBoundException ex) {
            Logger.getLogger(AltaProves.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MalformedURLException ex) {
            Logger.getLogger(AltaProves.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(AltaProves.class.getName()).log(Level.SEVERE, null, ex);
        }
        */
        // fi de llevar
    }

    Prova prova;
    int maxim;
    int minim;
    int codiUsuari;
    String txtNum;
    String txtResp;

    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("i18n/subsistema2/messagesSubsistema2"); // NOI18N
    RemoteInterface remoto;
    // llevar aixo en integrar
    private final String url = new String("rmi://localhost/RemoteInterface");
    // fi de llevar

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jButton4 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jFormattedTextField2 = new javax.swing.JFormattedTextField();
        jFormattedTextField3 = new javax.swing.JFormattedTextField();
        jFormattedTextField4 = new javax.swing.JFormattedTextField();
        jFormattedTextField5 = new javax.swing.JFormattedTextField();
        jFormattedTextField6 = new javax.swing.JFormattedTextField();
        jFormattedTextField7 = new javax.swing.JFormattedTextField();
        jFormattedTextField8 = new javax.swing.JFormattedTextField();
        jFormattedTextField9 = new javax.swing.JFormattedTextField();
        jFormattedTextField10 = new javax.swing.JFormattedTextField();
        jFormattedTextField11 = new javax.swing.JFormattedTextField();
        jFormattedTextField12 = new javax.swing.JFormattedTextField();
        jFormattedTextField13 = new javax.swing.JFormattedTextField();
        jFormattedTextField14 = new javax.swing.JFormattedTextField();
        jLabel20 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jFormattedTextField15 = new javax.swing.JFormattedTextField();
        jFormattedTextField16 = new javax.swing.JFormattedTextField();
        jComboBox1 = new javax.swing.JComboBox();
        jTextField3 = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("eOlympics - Gestio proves");

        jTextField1.setEditable(false);

        jLabel1.setText("Prova");

        jLabel2.setText("Num. Places");

        jLabel3.setText("Estat");

        jLabel4.setText("Inscripció des de");

        jLabel5.setText("Inscipció fins a");

        jLabel6.setText("Data alta");

        jLabel7.setText("Data Modificació");

        jLabel8.setText("Data Baixa");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "A", "B", "C", "D"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class
            };

            /*
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
            */

        });
        jScrollPane1.setViewportView(jTable1);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "A", "B", "C", "D"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class, java.lang.Boolean.class
            };
            /*
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
             */
        });
        jScrollPane2.setViewportView(jTable2);

        jLabel9.setText("Ronda Final");

        jLabel10.setText("Núm. preguntes");

        jLabel11.setText("Des de");

        jLabel12.setText("fins a");

        jLabel13.setText("Data modificació");

        jLabel14.setText("Data baixa");

        jLabel15.setText("Núm. preguntes");

        jLabel16.setText("Des de");

        jLabel17.setText("Fins a");

        jLabel18.setText("Data modificació");

        jLabel19.setText("Data Baixa");

        jToolBar1.setRollover(true);

        jButton4.setText("Nou");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton4);

        jButton1.setText("Editar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jButton2.setText("Cancel·lar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton2);

        jButton5.setText("Desar");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton5);

        jButton3.setText("Cercar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton3);

        jFormattedTextField1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField3.setEditable(false);
        jFormattedTextField3.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField4.setEditable(false);
        jFormattedTextField4.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField5.setEditable(false);
        jFormattedTextField5.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField6.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField7.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField8.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField9.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField10.setEditable(false);
        jFormattedTextField10.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField11.setEditable(false);
        jFormattedTextField11.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField12.setEditable(false);
        jFormattedTextField12.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField13.setEditable(false);
        jFormattedTextField13.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));

        jFormattedTextField14.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
        jFormattedTextField14.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jFormattedTextField14FocusLost(evt);
            }
        });

        jLabel22.setText("Eliminatoria");

        jFormattedTextField15.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jFormattedTextField15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormattedTextField15ActionPerformed(evt);
            }
        });
        jFormattedTextField15.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jFormattedTextField15FocusLost(evt);
            }
        });

        jFormattedTextField16.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(java.text.NumberFormat.getIntegerInstance())));
        jFormattedTextField16.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jFormattedTextField16FocusLost(evt);
            }
        });

        jTextField3.setEditable(false);

        jMenu2.setText("Arxiu");

        jMenuItem1.setText("Nou");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem2.setText("Editar");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem3.setText("Cancel·lar");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuItem4.setText("Desar");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem4);

        jMenuItem5.setText("Cercar");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel4)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(jLabel6)
                                    .addGap(16, 16, 16)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(18, 18, 18)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel13)
                                            .addComponent(jLabel11)
                                            .addComponent(jLabel10))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jFormattedTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(jLabel14)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(jFormattedTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jFormattedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(30, 30, 30)
                                                .addComponent(jLabel12)
                                                .addGap(18, 18, 18)
                                                .addComponent(jFormattedTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(jFormattedTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(41, 41, 41)
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(2, 2, 2)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(layout.createSequentialGroup()
                                                            .addGap(1, 1, 1)
                                                            .addComponent(jLabel15)
                                                            .addGap(18, 18, 18))
                                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                                            .addComponent(jLabel18)
                                                            .addGap(6, 6, 6)))
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(jLabel16)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                                    .addGroup(layout.createSequentialGroup()
                                                        .addComponent(jLabel22)
                                                        .addGap(22, 22, 22))))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jFormattedTextField15, 0, 0, Short.MAX_VALUE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel3)
                                            .addComponent(jFormattedTextField16, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                .addComponent(jFormattedTextField8, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                                .addComponent(jFormattedTextField10, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)))
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(6, 6, 6)
                                                .addComponent(jLabel19)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                        .addComponent(jFormattedTextField9, javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jFormattedTextField11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE))
                                                    .addComponent(jLabel20)))
                                            .addGroup(layout.createSequentialGroup()
                                                .addGap(12, 12, 12)
                                                .addComponent(jLabel17))
                                            .addGroup(layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGap(2, 2, 2))
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jFormattedTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel7)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jFormattedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(5, 5, 5)
                                    .addComponent(jLabel8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jFormattedTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(65, 65, 65))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(jLabel5)
                                    .addGap(18, 18, 18)
                                    .addComponent(jFormattedTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(57, 57, 57)
                .addComponent(jLabel1)
                .addGap(479, 479, 479))
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextField2)
                            .addComponent(jTextField1))
                        .addGap(20, 20, 20)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(jFormattedTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel20)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(jFormattedTextField15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jFormattedTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jFormattedTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jLabel22))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(jFormattedTextField14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel11)
                            .addComponent(jFormattedTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(jFormattedTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(jFormattedTextField16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jFormattedTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel16))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jFormattedTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel17))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel14)
                            .addComponent(jFormattedTextField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jFormattedTextField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel19))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jFormattedTextField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel18)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//cancel·lar
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    limpiar();
    bloquejar(false);
    if(prova!=null)
        mostraProva();
}//GEN-LAST:event_jButton2ActionPerformed

private void limpiar()
{
    jTextField1.setText(null);
    jTextField2.setText(null);        
    jTextField3.setText(null);        
    jFormattedTextField1.setText(null);
    jFormattedTextField2.setText(null);
    jFormattedTextField3.setText(null);
    jFormattedTextField4.setText(null);
    jFormattedTextField5.setText(null);
    jFormattedTextField6.setText(null);
    jFormattedTextField7.setText(null);
    jFormattedTextField8.setText(null);
    jFormattedTextField9.setText(null);
    jFormattedTextField10.setText(null);
    jFormattedTextField11.setText(null);
    jFormattedTextField12.setText(null);
    jFormattedTextField13.setText(null);
    jFormattedTextField14.setText(null);
    jFormattedTextField15.setText(null);
    jFormattedTextField16.setText(null);
    DefaultTableModel model = new DefaultTableModel();

    model.addColumn("núm.");
    model.addColumn("resp");
    jTable1.setModel(model);
    model = new DefaultTableModel();

    model.addColumn("núm.");
    model.addColumn("resp");
    jTable2.setModel(model);
    
    jComboBox1.addItem(Constants.PROVA_EN_PROCES_INSCRIPCIO);
    jComboBox1.addItem(Constants.PROVA_DESERTA);
    jComboBox1.addItem(Constants.PROVA_EN_COMPETICIO_PREVIA);
    jComboBox1.addItem(Constants.PROVA_EN_COMPETICIO_FINAL);
    jComboBox1.addItem(Constants.PROVA_EN_CLASSIFICACIO_PREVIA);
    jComboBox1.addItem(Constants.PROVA_EN_CLASSIFICACIO_FINAL);
    jComboBox1.addItem(Constants.PROVA_BAIXA);
    
    
    
    
        
}
// nou
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    bloquejar(true);
    limpiar();
    
    prova=null;
    jComboBox1.setSelectedItem(Constants.PROVA_EN_PROCES_INSCRIPCIO);
    jComboBox1.setEnabled(false);
    ocultarEliminatoria(false);
}//GEN-LAST:event_jButton4ActionPerformed



/*
 *  desar les dades
 * primer es comprova que les dades estiguin bé
 * despres segons si es nou o no, o s'ha agfegit coses es desa segons el cas
 * és llarg ja uqe la casuística es grossa.
 * els prints indiquen les possibilitats 
 * 
 */
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
    if(jTextField2.isEnabled()&&comprovar_camps()) // només si s'estava editant és possible fer-ho
    {
        bloquejar(false); 
        if (prova==null)
        {   // crear prova nova
            System.out.println("La prova és nova");
            prova=new Prova();
            prova.setDescripcio(jTextField2.getText());
            prova.setDataIniInscripcio((Date)jFormattedTextField1.getValue());
            prova.setDataFiInscripcio((Date)jFormattedTextField2.getValue());
            prova.setUsuariAlta(new Integer(codiUsuari));
            prova.setNombrePlaces(((Integer)jFormattedTextField15.getValue()));
            prova.setEstat(jComboBox1.getSelectedItem().toString());
                try {
                    prova=remoto.sub2alta(prova);
                    jTextField1.setText(prova.getIdProva().toString());
                    jFormattedTextField3.setValue(prova.getDataAlta());
                } catch (RemoteException ex) {
                    System.out.println("Problemes alta prova");
                }catch (EOlympicsException e) {
                    System.out.print("EOlympicsException");
                    System.out.println(bundle.getString("client.alta_prova"));
                }

            // desam la Ronda final
            // si tenim prova    
            if(prova.getIdProva().toString().length()!=0)
            {   
                System.out.println("intentam la ronda d'alta");
                Ronda ronda= new Ronda();
                ronda.setIdProva(prova.getIdProva());
                ronda.setTipusRonda("F");
                Ronda ronda2;
                    try {
                        System.out.println("miram si és nova");
                        ronda2 = remoto.sub2carregaRonda(ronda);
                        boolean nova=true;
                        if(ronda2!=null)
                        {
                            System.out.println("no és nova");
                            ronda=ronda2;
                            nova=false;
                        }
                        ronda.setNombrePreguntes(new Integer(jFormattedTextField14.getText().toString()));
                        ronda.setDataIniciRealitzacio((Date)jFormattedTextField6.getValue());
                        ronda.setDataFiRealitzacio((Date)jFormattedTextField7.getValue());
                        if(nova)                
                            ronda.setUsuariAlta(new Integer(codiUsuari));
                        else
                            ronda.setUsuariMod(new Integer(codiUsuari));

                            try {
                                if(nova)
                                    ronda=remoto.sub2alta(ronda);
                                else
                                    ronda=remoto.sub2modifica(ronda);

                                List<RespostaCorrecta> lista=new LinkedList();
                                for(int i=0;i<jTable1.getRowCount();i++)
                                {
                                    System.out.println("Afegint les respostes");
                                    RespostaCorrecta respostaCorrecta=new RespostaCorrecta();
                                    respostaCorrecta.setIdProva(ronda.getIdProva());
                                    respostaCorrecta.setTipusRonda(ronda.getTipusRonda());
                                    respostaCorrecta.setNumPregunta(new Integer(i+1));
                                    respostaCorrecta.setOpcioCorrecta(jTable1.getValueAt(i, 1).toString());
                                    lista.add(respostaCorrecta);
                                    jTable1.getValueAt(i, 1).toString();
                                }
                                remoto.sub2afegirRespostes(ronda, lista, codiUsuari);

                            } catch (RemoteException ex) {
                                System.out.println("problemes desant/modicant la ronda final");
                            }catch (EOlympicsException e) {
                               System.out.print("EOlympicsException");
                                System.out.println(bundle.getString("client.desant_ronda_final"));
                            }                    
                    } catch (RemoteException ex) {
                        System.out.println("Problemes comprovnat existencia ronda  final");
                    }catch (EOlympicsException e) {
                        System.out.print("EOlympicsException");
                        System.out.println(bundle.getString("client.carregant_ronda"));
                            }
            }
        }
        else
        { // modificar prova existent
            System.out.println("modificam prova existent");
            prova.setDescripcio(jTextField2.getText());
            prova.setDataIniInscripcio((Date)jFormattedTextField1.getValue());
            prova.setDataFiInscripcio((Date)jFormattedTextField2.getValue());
            prova.setUsuariMod(new Integer(codiUsuari));
            prova.setNombrePlaces(new Integer(jFormattedTextField15.getValue().toString()));
            prova.setEstat(jComboBox1.getSelectedItem().toString());
                try {
                    prova=remoto.sub2modifica(prova);
                    jFormattedTextField4.setValue(prova.getDataMod());
                } catch (RemoteException ex) {
                    System.out.println("problemes modificant prova");
                }catch (EOlympicsException e) {
                                System.out.print("EOlympicsException");
                                System.out.println(bundle.getString("client.modificar_prova"));
                }
                // i la ronda
                Ronda ronda= new Ronda();
                ronda.setTipusRonda("F");
                ronda.setIdProva(prova.getIdProva());
                try {
                    System.out.println("cercam la ronda final");
                    ronda=remoto.sub2carregaRonda(ronda);                
                    ronda.setNombrePreguntes(new Integer(jFormattedTextField14.getText().toString()));
                    ronda.setDataIniciRealitzacio((Date)jFormattedTextField6.getValue());
                    ronda.setDataFiRealitzacio((Date)jFormattedTextField7.getValue());
                    ronda.setUsuariMod(new Integer(codiUsuari));
                    try {
                        System.out.println("modificam la final");
                        ronda=remoto.sub2modifica(ronda);
                        jFormattedTextField12.setValue(ronda.getDataMod());
                        List<RespostaCorrecta> lista=new LinkedList();
                        for(int i=0;i<jTable1.getRowCount();i++)
                        {
                            System.out.println("modificam les respostes "+jTable1.getValueAt(i, 1).toString());
                            RespostaCorrecta respostaCorrecta=new RespostaCorrecta();
                            respostaCorrecta.setIdProva(ronda.getIdProva());
                            respostaCorrecta.setTipusRonda(ronda.getTipusRonda());
                            respostaCorrecta.setNumPregunta(new Integer(i+1));
                            respostaCorrecta.setOpcioCorrecta(jTable1.getValueAt(i, 1).toString());
                            lista.add(respostaCorrecta);
                        }
                        remoto.sub2afegirRespostes(ronda, lista, codiUsuari);


                    } catch (RemoteException ex) {
                        System.out.println("problemes modificant la ronda");
                    }catch (EOlympicsException e) {
                        System.out.print("EOlympicsException");
                        System.out.println(bundle.getString("client.modificant_ronda"));
                    }

                } catch (RemoteException ex) {
                    System.out.println("Problemes carregant la ronda");
                }catch (EOlympicsException e) {
                        System.out.print("EOlympicsException");
                        System.out.println(bundle.getString("client.carregant_ronda"));
                    }
                try {
                    System.out.println("cercam si ha de tenir eliminatoria");
                    if(remoto.sub2recomptaInscrits(prova).intValue()>Constants.NUM_CLASSIFICATS_RONDA_FINAL)
                    {
                        ronda= new Ronda();
                        ronda.setTipusRonda("E");
                        ronda.setIdProva(prova.getIdProva());                        
                        Ronda ronda2=remoto.sub2carregaRonda(ronda);
                        if(ronda2!=null)
                        {       //modificar l'actual                        
                            System.out.println("modificam ronda eliminatoria");                        
                            ronda2.setNombrePreguntes(new Integer(jFormattedTextField16.getText().toString()));
                            ronda2.setDataIniciRealitzacio((Date)jFormattedTextField8.getValue());
                            ronda2.setDataFiRealitzacio((Date)jFormattedTextField9.getValue());
                            ronda2.setUsuariMod(new Integer(codiUsuari));
                            try{
                                ronda2=remoto.sub2modifica(ronda2);                        
                            }catch (EOlympicsException e) {
                                System.out.print("EOlympicsException");
                                System.out.println(bundle.getString("client.modifica_ronda"));
                            }    
                            List<RespostaCorrecta> lista=new LinkedList();
                            for(int i=0;i<jTable2.getRowCount();i++)
                            {
                                System.out.println("modificam les respostes eliminatoria");
                                RespostaCorrecta respostaCorrecta=new RespostaCorrecta();
                                respostaCorrecta.setIdProva(ronda.getIdProva());
                                respostaCorrecta.setTipusRonda(ronda.getTipusRonda());
                                respostaCorrecta.setNumPregunta(new Integer(i+1));
                                respostaCorrecta.setOpcioCorrecta(jTable2.getValueAt(i, 1).toString());                                
                                lista.add(respostaCorrecta);
                            }
                            try{
                                remoto.sub2afegirRespostes(ronda2, lista, codiUsuari);
                            }catch (EOlympicsException e) {
                                System.out.print("EOlympicsException");
                                System.out.println(bundle.getString("client.afegir_respostes"));
                            }
                        }    
                        else
                        {       // crear nova ronsa eliminatoria                    
                            System.out.println("inserim ronda eliminatoria nova");
                            ronda.setTipusRonda("E");
                            ronda.setIdProva(prova.getIdProva());
                            ronda.setNombrePreguntes(new Integer(jFormattedTextField16.getText().toString()));
                            ronda.setDataIniciRealitzacio((Date)jFormattedTextField8.getValue());
                            ronda.setDataFiRealitzacio((Date)jFormattedTextField9.getValue());
                            ronda.setUsuariAlta(new Integer(codiUsuari));
                            try{
                                ronda=remoto.sub2alta(ronda);
                            }catch (EOlympicsException e) {
                                System.out.print("EOlympicsException");
                                System.out.println(bundle.getString("client.alta_ronda"));
                            }
                            List<RespostaCorrecta> lista=new LinkedList();
                            for(int i=0;i<jTable2.getRowCount();i++)
                            {
                                System.out.println("afegim les respostes eliminatoria");
                                RespostaCorrecta respostaCorrecta=new RespostaCorrecta();
                                respostaCorrecta.setIdProva(ronda.getIdProva());
                                respostaCorrecta.setTipusRonda(ronda.getTipusRonda());
                                respostaCorrecta.setNumPregunta(new Integer(i+1));
                                respostaCorrecta.setOpcioCorrecta(jTable2.getValueAt(i, 1).toString());
                                lista.add(respostaCorrecta);
                            }
                            try{
                                remoto.sub2afegirRespostes(ronda, lista, codiUsuari);
                            }catch (EOlympicsException e) {
                                System.out.print("EOlympicsException");
                                System.out.println(bundle.getString("client.afegir_respostes"));
                            }

                        }
                    }
                } catch (RemoteException ex) {
                    System.out.println("problema obtenin nombre d'inscrits");
                }catch (EOlympicsException e) {
                        System.out.print("EOlympicsException");
                        System.out.println(bundle.getString("client.obtenint_inscrits"));
                }
        }
    }
}//GEN-LAST:event_jButton5ActionPerformed


/* bloquejar els controls
 * @param boolean mostrar
 * 
 */
private void bloquejar(boolean mostrar)
{

    jTextField2.setEnabled(mostrar);
    jFormattedTextField1.setEnabled(mostrar);
    jFormattedTextField2.setEnabled(mostrar);
    jFormattedTextField6.setEnabled(mostrar);
    jFormattedTextField7.setEnabled(mostrar);
    jFormattedTextField8.setEnabled(mostrar);
    jFormattedTextField9.setEnabled(mostrar);
    jFormattedTextField14.setEnabled(mostrar);
    jFormattedTextField15.setEnabled(mostrar);
    jFormattedTextField16.setEnabled(mostrar);
    jTable1.setEnabled(mostrar);
    jTable2.setEnabled(mostrar);
    

    jTextField2.setEditable(mostrar);
    jComboBox1.setEnabled(mostrar);
    jFormattedTextField1.setEditable(mostrar);
    jFormattedTextField2.setEditable(mostrar);
    jFormattedTextField6.setEditable(mostrar);
    jFormattedTextField7.setEditable(mostrar);
    jFormattedTextField8.setEditable(mostrar);
    jFormattedTextField9.setEditable(mostrar);
    jFormattedTextField14.setEditable(mostrar);
    jFormattedTextField15.setEditable(mostrar);
    jFormattedTextField16.setEditable(mostrar);
    
    jTextField1.setEnabled(false);
    jFormattedTextField10.setEnabled(false);
    jFormattedTextField11.setEnabled(false);
    jFormattedTextField12.setEnabled(false);
    jFormattedTextField13.setEnabled(false);
    jFormattedTextField3.setEnabled(false);
    jFormattedTextField4.setEnabled(false);
    jFormattedTextField5.setEnabled(false);
}


private void jFormattedTextField15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextField15ActionPerformed

    
}//GEN-LAST:event_jFormattedTextField15ActionPerformed
/* comprovacio numero de places */
private void jFormattedTextField15FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextField15FocusLost

       
    if(jFormattedTextField15.getText().length()!=0)
         if((new Integer(jFormattedTextField15.getText()).intValue()<minim)||(new Integer(jFormattedTextField15.getText()).intValue()>maxim))
         {
             System.out.println("minin"+minim+" maxim"+maxim+" hi ha "+new Integer(jFormattedTextField15.getText()).intValue());
             jFormattedTextField15.setValue(null);
         }

}//GEN-LAST:event_jFormattedTextField15FocusLost

/*
 * comprovació que el numero de preguntes sigui valid
 */
private void jFormattedTextField14FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextField14FocusLost

    if(jFormattedTextField14.getText().length()!=0)
    {
        int i=new Integer(jFormattedTextField14.getText().toString()).intValue();
        if(i<6 || i>15){
            jFormattedTextField14.setValue(null);
        }
        else
        {

        DefaultTableModel model = new DefaultTableModel();

        model.addColumn(txtNum);
        model.addColumn(txtResp);        
        jTable1.setModel(model);
        for(int j=1;j<=i;j++)
        {
            String[] cols = {new Integer(j).toString(),""};
            model.addRow(cols);
        }
        jTable1.setModel(model);
            
        }
    }
}//GEN-LAST:event_jFormattedTextField14FocusLost


//botó cerca
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
    bloquejar(false);
    CercarProva cercarProva=new CercarProva(remoto,this);
    this.setVisible(false);
    prova=null;
    cercarProva.setVisible(true);
}//GEN-LAST:event_jButton3ActionPerformed


// editar
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    bloquejar(true);
    
}//GEN-LAST:event_jButton1ActionPerformed

private boolean comprovar_camps(){
    boolean correcte=true;
    jTextField3.setText(null);
    if(jTextField2.getText().length()==0)
    {     
        jTextField3.setText(bundle.getString("client.errada1"));
        return false;
    }
        
    if(jFormattedTextField15.getText().toString().length()==0)
    {        
        jTextField3.setText(bundle.getString("client.errada2"));
        return false;
    }
        
    if(jFormattedTextField1.getText().toString().length()==0)
    {        
        jTextField3.setText(bundle.getString("client.errada3"));
        return false;
    }
    if(jFormattedTextField2.getText().toString().length()==0)
    {        
        jTextField3.setText(bundle.getString("client.errada4"));
        return false;
    }
    if(((Date)jFormattedTextField1.getValue()).after((Date)jFormattedTextField2.getValue()))
    {
        jTextField3.setText(bundle.getString("client.errada5"));
        return false;        
    }
    if(jFormattedTextField14.getText().toString().length()==0)
    {        
        jTextField3.setText(bundle.getString("client.errada6"));
        return false;
    }
    if(jFormattedTextField6.getText().toString().length()==0)
    {        
        jTextField3.setText(bundle.getString("client.errada7"));
        return false;
    }
    if(jFormattedTextField7.getText().toString().length()==0)
    {     
        jTextField3.setText(bundle.getString("client.errada8"));
        return false;
    }
    if(((Date)jFormattedTextField6.getValue()).after((Date)jFormattedTextField7.getValue()))
    {
        jTextField3.setText(bundle.getString("client.errada9"));
        return false;

    }
    int i=0;
    while(i<jTable1.getRowCount()-1)
    {
        System.out.println("vaig per "+i+" "+jTable1.getValueAt(i,1).toString());
        if((jTable1.getValueAt(i,1).toString().length()!=1)||!((jTable1.getValueAt(i,1).toString().contains("a"))||(jTable1.getValueAt(i,1).toString().contains("b"))||(jTable1.getValueAt(i,1).toString().contains("c")||(jTable1.getValueAt(i,1).toString().contains("d")) )))
        {
            jTextField3.setText(bundle.getString("client.errada10")+(i+1)+bundle.getString("client.errada11"));
            return false;
        }
        i++;        
    }
    if(new Integer(jFormattedTextField14.getText().toString()).intValue()!=jTable1.getRowCount())
    {
        jTextField3.setText(bundle.getString("client.errada18"));
        return false;
    }

        
    if(jFormattedTextField16.isVisible())
    {
        // comprovar les dades de la ronda inicial
        
        if(jFormattedTextField16.getText().toString().length()==0)
        {        
            jTextField3.setText(bundle.getString("client.errada12"));
            return false;
        }
        if(jFormattedTextField8.getText().toString().length()==0)
        {        
            jTextField3.setText(bundle.getString("client.errada13"));
            return false;
        }
        if(jFormattedTextField9.getText().toString().length()==0)
        {     
            jTextField3.setText(bundle.getString("client.errada1"));
            return false;
        }
        if(((Date)jFormattedTextField8.getValue()).after((Date)jFormattedTextField9.getValue()))
        {
            jTextField3.setText(bundle.getString("client.errada14"));
            return false;
        }

        // ara comprovam les preguntes
        i=0;
        while(i<jTable2.getRowCount()-1)
        {
            System.out.println("vaig per "+i+" "+jTable2.getValueAt(i,1).toString());
            if((jTable2.getValueAt(i,1).toString().length()!=1)||!((jTable2.getValueAt(i,1).toString().contains("a"))||(jTable2.getValueAt(i,1).toString().contains("b"))||(jTable2.getValueAt(i,1).toString().contains("c")||(jTable2.getValueAt(i,1).toString().contains("d")) )))
            {
                jTextField3.setText(bundle.getString("client.errada15")+(i+1)+bundle.getString("client.errada11"));
                return false;
            }
            i++;        
        }
        if(new Integer(jFormattedTextField16.getText().toString()).intValue()!=jTable2.getRowCount())
        {
            jTextField3.setText(bundle.getString("client.errada19"));
            return false;
        }
        
    }
 
    // comprovar canvis d'estat
    if((prova!=null)&&!(prova.getEstat().equals(jComboBox1.getSelectedItem().toString())))
    {
        System.out.println("1");
        if(!jComboBox1.getSelectedItem().toString().equals(Constants.PROVA_BAIXA))
        {         
                jTextField3.setText(bundle.getString("client.errada16"));
                return false;            
        }
        else
        {
            System.out.println("3");
            if((prova.getEstat().equals(Constants.PROVA_EN_COMPETICIO_PREVIA))||prova.getEstat().equals(Constants.PROVA_EN_COMPETICIO_FINAL))
            {
                System.out.println("4");
                jTextField2.setText(bundle.getString("client.errada17"));
                return false;                        
            }
        }
    }  
    return correcte;
    
}
        

        

/*
 * comprovar número de preguntes correcte
 */
private void jFormattedTextField16FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextField16FocusLost

    if(jFormattedTextField16.getText().length()!=0)
    {
            int i=new Integer(jFormattedTextField16.getText().toString()).intValue();
            if(i<6 || i>15){
                jFormattedTextField16.setValue(null);
        }
        else
        {
            DefaultTableModel model = new DefaultTableModel();

            model.addColumn(txtNum);
            model.addColumn(txtResp);        
            jTable2.setModel(model);
            for(int j=1;j<=i;j++)
            {
                String[] cols = {new Integer(j).toString(),""};
                model.addRow(cols);
            }
            jTable2.setModel(model);
        }
    }
}//GEN-LAST:event_jFormattedTextField16FocusLost
// opcions de menus simplement simular pulsació botons 
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

     jButton1ActionPerformed(evt);    
}//GEN-LAST:event_jMenuItem1ActionPerformed

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed

    jButton1ActionPerformed(evt);
}//GEN-LAST:event_jMenuItem2ActionPerformed

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed

    jButton2ActionPerformed(evt);
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed

    jButton5ActionPerformed(evt);
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed

    jButton3ActionPerformed(evt);
}//GEN-LAST:event_jMenuItem5ActionPerformed

// fi opcions menús


/*
 * mostrar ocultar la part de la prova eliminatòria
 * @param boolean mostra
 */

    private void ocultarEliminatoria(boolean mostra){
        jFormattedTextField16.setVisible(mostra);
        jFormattedTextField8.setVisible(mostra);
        jFormattedTextField10.setVisible(mostra);
        jFormattedTextField9.setVisible(mostra);
        jFormattedTextField11.setVisible(mostra);
        jLabel22.setVisible(mostra);
        jLabel15.setVisible(mostra);
        jLabel16.setVisible(mostra);
        jLabel17.setVisible(mostra);
        jLabel18.setVisible(mostra);
        jLabel19.setVisible(mostra);
        jTable2.setVisible(mostra);
    }



    /*
    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(AltaProves.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(AltaProves.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(AltaProves.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(AltaProves.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {            
            public void run() {
                new AltaProves(2).setVisible(true);
            }
        });
    }
    */



    public Prova getProva() {
        return prova;
    }

    
    /*
     * setter es fa servir des de la pantalla de cerca per tant quan torna mostrar la prova cercada
     * o fer net si escau
     */
    public void setProva(Prova prova) {
        this.prova = prova;
        if (prova !=null)
        {
            mostraProva();
        }
        else
        {
            limpiar();
        }
    }
    
    
    /*
     * mostra una prova amb les seves dades
     * (pinta la prova ronda i preguntes amb la informació obtinguda)
     * carrega del client les dades necessàries
     */

    private void mostraProva()
    {
        jTextField1.setText(prova.getIdProva().toString());
        jTextField2.setText(prova.getDescripcio());
        jFormattedTextField15.setValue(prova.getNombrePlaces());
        jFormattedTextField1.setValue(prova.getDataIniInscripcio());
        jFormattedTextField2.setValue(prova.getDataFiInscripcio());
        jFormattedTextField3.setValue(prova.getDataAlta());
        jFormattedTextField4.setValue(prova.getDataMod());
        jFormattedTextField5.setValue(prova.getDataBaixa());
        jComboBox1.setSelectedItem(prova.getEstat());                
        
        try {
            int inscrits=(remoto.sub2recomptaInscrits(prova)).intValue();
            if (inscrits>Constants.NUM_CLASSIFICATS_RONDA_FINAL)
                ocultarEliminatoria(true);
                Ronda ronda=remoto.sub2carregaRonda(new Ronda(prova.getIdProva(),"F"));
                jFormattedTextField14.setValue(ronda.getNombrePreguntes());
                jFormattedTextField6.setValue(ronda.getDataIniciRealitzacio());
                jFormattedTextField7.setValue(ronda.getDataFiRealitzacio());
                jFormattedTextField12.setValue(ronda.getDataMod());
                jFormattedTextField13.setValue(ronda.getDataBaixa());  
                List<RespostaCorrecta> lista=remoto.sub2getLlistaRespostes(ronda);
                DefaultTableModel model = new DefaultTableModel();
                model.addColumn(txtNum);
                model.addColumn(txtResp);                
                for(RespostaCorrecta resposta: lista)
                {
                    String[] cols = {resposta.getNumPregunta().toString(),resposta.getOpcioCorrecta()};
                    model.addRow(cols);
                }
                jTable1.setModel(model);   
                
        } catch (RemoteException ex) {
            Logger.getLogger(AltaProves.class.getName()).log(Level.SEVERE, null, ex);
        }catch (EOlympicsException e) {
            System.out.print("EOlympicsException");
            System.out.println(bundle.getString("client.obtenint_inscrits"));
        }
        
        try {
            if(remoto.sub2recomptaInscrits(prova).intValue()>Constants.NUM_CLASSIFICATS_RONDA_FINAL)
            {
                System.out.println("posar eliminatoria");
                ocultarEliminatoria(true);
                try {
                    Ronda ronda=remoto.sub2carregaRonda(new Ronda(prova.getIdProva(),"E"));
                    if(ronda!=null)
                    {                           
                        jFormattedTextField16.setValue(ronda.getNombrePreguntes());
                        jFormattedTextField8.setValue(ronda.getDataIniciRealitzacio());
                        jFormattedTextField9.setValue(ronda.getDataFiRealitzacio());
                        jFormattedTextField10.setValue(ronda.getDataMod());
                        jFormattedTextField11.setValue(ronda.getDataBaixa());
                        List<RespostaCorrecta> lista=remoto.sub2getLlistaRespostes(ronda);
                        DefaultTableModel model = new DefaultTableModel();
                        model.addColumn(txtNum);
                        model.addColumn(txtResp);                
                        for(RespostaCorrecta resposta: lista)
                        {
                            String[] cols = {resposta.getNumPregunta().toString(),resposta.getOpcioCorrecta()};
                            model.addRow(cols);
                        }
                        jTable2.setModel(model);   

                    }
                    else
                    {
                        jFormattedTextField16.setValue(null);
                        jFormattedTextField8.setValue(null);
                        jFormattedTextField9.setValue(null);
                        jFormattedTextField10.setValue(null);
                        jFormattedTextField11.setValue(null);
                    }
                } catch (RemoteException ex) {
                    System.out.println("problema carregant la ronda");
                }
            }
            else
                ocultarEliminatoria(false);
        } catch (RemoteException ex) {
            System.out.println("Problema obtenint inscrita");
        }catch (EOlympicsException e) {
            System.out.print("EOlympicsException");
            System.out.println(bundle.getString("client.obtenint_inscrits"));
       }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JFormattedTextField jFormattedTextField10;
    private javax.swing.JFormattedTextField jFormattedTextField11;
    private javax.swing.JFormattedTextField jFormattedTextField12;
    private javax.swing.JFormattedTextField jFormattedTextField13;
    private javax.swing.JFormattedTextField jFormattedTextField14;
    private javax.swing.JFormattedTextField jFormattedTextField15;
    private javax.swing.JFormattedTextField jFormattedTextField16;
    private javax.swing.JFormattedTextField jFormattedTextField2;
    private javax.swing.JFormattedTextField jFormattedTextField3;
    private javax.swing.JFormattedTextField jFormattedTextField4;
    private javax.swing.JFormattedTextField jFormattedTextField5;
    private javax.swing.JFormattedTextField jFormattedTextField6;
    private javax.swing.JFormattedTextField jFormattedTextField7;
    private javax.swing.JFormattedTextField jFormattedTextField8;
    private javax.swing.JFormattedTextField jFormattedTextField9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables
}
